//
//  LeftMenuViewController.m
//  Staff
//
//  Created by HSBC_XiAn_Core on 4/1/15.
//
//

#import "LeftMenuViewController.h"
#import "MenuTableViewCell.h"
#import "MenuObject.h"
#import "AppDelegate.h"
#import "MainViewController.h"
#import "REFrostedViewController.h"
#import "UIViewController+REFrostedViewController.h"


@interface LeftMenuViewController ()

@end

@implementation LeftMenuViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view from its nib.
    
     NSString *userName = [[NSUserDefaults standardUserDefaults]objectForKey:@"userName"];
    _headerLabel.text = [NSString stringWithFormat:@"Welcome,%@!",userName];
    _tableDataSource = [NSMutableArray array];
    
    MenuObject *menu1 = [[MenuObject alloc] init];
    menu1.icon = @"walkathon.png";
    menu1.label = @"Walkathon";
    menu1.action = @"push_hsbc_150";
    [_tableDataSource addObject:menu1];
    
    
    MenuObject *menu2 = [[MenuObject alloc] init];
    menu2.icon = @"viewwall.png";
    menu2.label = @"Newsroom";
    menu2.action = @"push_newsroom";
    [_tableDataSource addObject:menu2];
    
    MenuObject *menu3 = [[MenuObject alloc] init];
    menu3.icon = @"calendar.png";
    menu3.label = @"Activities";
    menu3.action = @"push_activities";
    //[_tableDataSource addObject:menu3];
    
    MenuObject *menu4 = [[MenuObject alloc] init];
    menu4.icon = @"ar.png";
    menu4.label = @"Discovery";
    menu4.action = @"push_AR";
    //[_tableDataSource addObject:menu4];
    
    MenuObject *menu5 = [[MenuObject alloc] init];
    menu5.icon = @"gl.png";
    menu5.label = @"Green Laisee";
    menu5.action = @"push_Laisee";
    //[_tableDataSource addObject:menu5];
    
    MenuObject *menu6 = [[MenuObject alloc] init];
    menu6.icon = @"RR.png";
    menu6.label = @"Rewards & Recognition";
    menu6.action = @"push_voting";
    //[_tableDataSource addObject:menu6];
    
    MenuObject *menu7 = [[MenuObject alloc] init];
    menu7.icon = @"settings.png";
    menu7.label = @"Settings";
    menu7.action = @"push_setting";
    [_tableDataSource addObject:menu7];

    
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

- (IBAction)logoff:(id)sender {
    [(MainViewController *)[(AppDelegate *)[[UIApplication sharedApplication] delegate] viewController] changeMenuBackFromGreenWithMenuId :@"push_logon"];
    
    NSLog(@"logoff");
    [[(AppDelegate *)[[UIApplication sharedApplication] delegate] viewController].navigationController popViewControllerAnimated:NO];

}

#pragma mark -- UI Table View
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{

    return [_tableDataSource count];
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    NSUInteger row = [indexPath row];
    MenuObject *item = [_tableDataSource objectAtIndex:row];
    
    static NSString *functionCellIdentifier = @"PublicHomeMenuTableCellIdentifier";
    
    MenuTableViewCell* menuTableCell = [tableView dequeueReusableCellWithIdentifier: functionCellIdentifier];
    
    if (menuTableCell == nil)
    {
        NSArray *nib = [[NSBundle mainBundle] loadNibNamed:@"MenuTableViewCell"
                                                     owner:self options:nil];
        if ([nib count] > 0)
        {
            menuTableCell = [nib objectAtIndex:0];
        }
        else
        {
            DebugLog(@"failed to load PublicHomeMeunTableCell nib file!");
        }
    }
    menuTableCell.selectionStyle = UITableViewCellSelectionStyleNone;
    menuTableCell.imageIcon.image = [UIImage imageNamed:item.icon];
    menuTableCell.titleLable.text = item.label;

    return menuTableCell;
}

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{

    NSUInteger row = [indexPath row];
    MenuObject *item = [_tableDataSource objectAtIndex:row];
    
    if ([@"push_hsbc_150" isEqualToString:item.action ]) {
        [self.frostedViewController hideMenuViewController];
    }else{
        [(MainViewController *)[(AppDelegate *)[[UIApplication sharedApplication] delegate] viewController] changeMenuBackFromGreenWithMenuId :item.action];
        
        NSLog(@"didSelectRowAtIndexPath");
        [[(AppDelegate *)[[UIApplication sharedApplication] delegate] viewController].navigationController popViewControllerAnimated:NO];
    
    }

}

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
    return 52.0;
}


@end
